import React from 'react'
import ReactTypes from 'prop-types'
import Son from './Son.jsx'
export default class Father extends React.Component{
    constructor(props){
       super(props);
  
       this.state={
         msg:[
             {name:'wxg',content:'座个好人'},
             {name:'wwq',content:'跟着党走'}
         ],
         color:'pink'
       }

    }
   
    render(){
    
      return <div>
             评论人：<input type="text" ref="person"/> <br/>
            评论内容：<textarea name="" ref="content" ></textarea><br/>
            <input type="button" value="发表评论" onClick={this.submitComment.bind(this)}/>
        
               <Son ></Son>
                    

         
        
      </div>
    }
    submitComment(){
        var o = {};
        var info = this.state.msg;
        o.name=this.refs.person.value;
        o.content =this.refs.content.value;
        console.log(info)
        info.unshift(o);
        this.refs.person.value=this.refs.content.value="";
   
      
        this.setState({
            msg:info
        })
        

    }
    getChildContext(){
        return{
            color:this.state.color
        }
    }
    static childContextTypes={
        color:ReactTypes.string
    }
 
    

  }
